<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Config_Ini - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.config.adapters.ini.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.config.adapters.ini.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.config.theory_of_operation.html">Theory of Operation</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.config.html">Zend_Config</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.config.adapters.json.html">Zend_Config_Json</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.config.adapters.ini" class="section"><div class="info"><h1 class="title">Zend_Config_Ini</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Config_Ini</span> enables developers to store configuration data in a
        familiar <acronym class="acronym">INI</acronym> format and read them in the application by using nested
        object property syntax. The <acronym class="acronym">INI</acronym> format is specialized to provide both
        the ability to have a hierarchy of configuration data keys and inheritance between
        configuration data sections. Configuration data hierarchies are supported by separating the
        keys with the dot or period character (&quot;<em class="emphasis">.</em>&quot;). A section may extend or
        inherit from another section by following the section name with a colon character
        (&quot;<em class="emphasis">:</em>) and the name of the section from which data are to be inherited.
    </p>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Parsing the INI File</b><br /></span>
        

        <p class="para">
            <span class="classname">Zend_Config_Ini</span> utilizes the <a href="http://php.net/parse_ini_file" class="link external">&raquo;  <span class="methodname">parse_ini_file()</span></a>
            <acronym class="acronym">PHP</acronym> function. Please review this documentation to be aware of its
            specific behaviors, which propagate to <span class="classname">Zend_Config_Ini</span>, such as
            how the special values of &quot;<b><tt>TRUE</tt></b>&quot;, &quot;<b><tt>FALSE</tt></b>&quot;,
            &quot;yes&quot;, &quot;no&quot;, and &quot;<b><tt>NULL</tt></b>&quot; are handled.
        </p>
    </p></blockquote>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Key Separator</b><br /></span>
        

        <p class="para">
            By default, the key separator character is the period character
            (&quot;<em class="emphasis">.</em>&quot;). This can be changed, however, by changing the
            <var class="varname">$options</var> key <span class="property">nestSeparator</span> when constructing
            the <span class="classname">Zend_Config_Ini</span> object. For example:
        </p>

        <pre class="programlisting brush: php">
$options[&#039;nestSeparator&#039;] = &#039;:&#039;;
$config = new Zend_Config_Ini(&#039;/path/to/config.ini&#039;,
                              &#039;staging&#039;,
                              $options);
</pre>

    </p></blockquote>

    <div class="example" id="zend.config.adapters.ini.example.using"><div class="info"><p><b>Example #1 Using Zend_Config_Ini</b></p></div>
        

        <div class="example-contents"><p>
            This example illustrates a basic use of <span class="classname">Zend_Config_Ini</span> for
            loading configuration data from an <acronym class="acronym">INI</acronym> file. In this example there
            are configuration data for both a production system and for a staging system. Because
            the staging system configuration data are very similar to those for production, the
            staging section inherits from the production section. In this case, the decision is
            arbitrary and could have been written conversely, with the production section
            inheriting from the staging section, though this may not be the case for more complex
            situations. Suppose, then, that the following configuration data are contained in
            <var class="filename">/path/to/config.ini</var>:
        </p></div>

        <pre class="programlisting brush: ini">
; Production site configuration data
[production]
webhost                  = www.example.com
database.adapter         = pdo_mysql
database.params.host     = db.example.com
database.params.username = dbuser
database.params.password = secret
database.params.dbname   = dbname

; Staging site configuration data inherits from production and
; overrides values as necessary
[staging : production]
database.params.host     = dev.example.com
database.params.username = devuser
database.params.password = devsecret
</pre>


        <div class="example-contents"><p>
            Next, assume that the application developer needs the staging configuration data from
            the <acronym class="acronym">INI</acronym> file. It is a simple matter to load these data by specifying
            the <acronym class="acronym">INI</acronym> file and the staging section:
        </p></div>

        <pre class="programlisting brush: php">
$config = new Zend_Config_Ini(&#039;/path/to/config.ini&#039;, &#039;staging&#039;);

echo $config-&gt;database-&gt;params-&gt;host;   // prints &quot;dev.example.com&quot;
echo $config-&gt;database-&gt;params-&gt;dbname; // prints &quot;dbname&quot;
</pre>

    </div>

    <blockquote class="note"><p><b class="note">Note</b>: 
        <table id="zend.config.adapters.ini.table" class="doctable table"><div class="info"><caption><b>Zend_Config_Ini Constructor Parameters</b></caption></div>
            

            
                <thead valign="middle">
                    <tr valign="middle">
                        <th>Parameter</th>
                        <th>Notes</th>
                    </tr>

                </thead>


                <tbody valign="middle" class="tbody">
                    <tr valign="middle">
                        <td align="left"><var class="varname">$filename</var></td>
                        <td align="left">The <acronym class="acronym">INI</acronym> file to load.</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><var class="varname">$section</var></td>

                        <td align="left">
                            The [section] within the <acronym class="acronym">INI</acronym> file that is to be
                            loaded. Setting this parameter to <b><tt>NULL</tt></b> will load
                            all sections. Alternatively, an array of section names may be supplied
                            to load multiple sections.
                        </td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">
                            <var class="varname">$options</var> (default <b><tt>FALSE</tt></b>)
                        </td>

                        <td align="left">
                            Options array. The following keys are supported:

                            <ul class="itemizedlist">
                                <li class="listitem">
                                    <p class="para">
                                        <em class="emphasis"><span class="property">allowModifications</span></em>:
                                        Set to <b><tt>TRUE</tt></b> to allow subsequent
                                        modification of loaded configuration data in-memory.
                                        Defaults to <b><tt>NULL</tt></b>
                                    </p>
                                </li>

                                <li class="listitem">
                                    <p class="para">
                                        <em class="emphasis"><span class="property">nestSeparator</span></em>: Set
                                        to the character to be used as the nest separator. Defaults
                                        to &quot;.&quot;
                                    </p>
                                </li>
                            </ul>
                        </td>
                    </tr>

                </tbody>
            
        </table>

    </p></blockquote>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.config.theory_of_operation.html">Theory of Operation</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.config.html">Zend_Config</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.config.adapters.json.html">Zend_Config_Json</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.config.html">Zend_Config</a></li>
  <li><a href="zend.config.introduction.html">Introduction</a></li>
  <li><a href="zend.config.theory_of_operation.html">Theory of Operation</a></li>
  <li class="active"><a href="zend.config.adapters.ini.html">Zend_Config_Ini</a></li>
  <li><a href="zend.config.adapters.json.html">Zend_Config_Json</a></li>
  <li><a href="zend.config.adapters.xml.html">Zend_Config_Xml</a></li>
  <li><a href="zend.config.adapters.yaml.html">Zend_Config_Yaml</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>